import java.awt.Component;

import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * Title:  Style.java
 * Description:  This class is the class to offer a Style menu for GUI of group
 * Copyright:    Copyright (c) 2009
 * @author WANG Jiechao
 * @version 1.0
 */
public class Style extends JMenu {
  //JMenu file;
  private JCheckBoxMenuItem cbMenuItem1;//menu items to choose style
  private JCheckBoxMenuItem cbMenuItem2;//menu items to choose style
  private JCheckBoxMenuItem cbMenuItem3;//menu items to choose style
  private JCheckBoxMenuItem cbMenuItem4;//menu items to choose style
  String selectedStyle;
  
  /**
   * This constructor create some menu items for menu of style.
   */    
  public Style(){
    super("Style");                                                 //The first menu in the menu bar
    this.setMnemonic(83);                                           //Sets the keyboard mnemonic on the current model

    ButtonGroup localButtonGroup = new ButtonGroup();              //Creat a group of two check box buttons                                        
    
    this.cbMenuItem1 = new JCheckBoxMenuItem("Metal");              //A button used for activating look and feel 1    
    this.cbMenuItem1.setMnemonic(85);
    add(this.cbMenuItem1);
    localButtonGroup.add(this.cbMenuItem1);
    
    this.cbMenuItem2 = new JCheckBoxMenuItem("Windows");            //A button used for activating look and feel 2
    this.cbMenuItem2.setMnemonic(68);
    add(this.cbMenuItem2);
    localButtonGroup.add(this.cbMenuItem2);
    
    this.cbMenuItem3 = new JCheckBoxMenuItem("Nimbus");             //A button used for activating look and feel 3
    this.cbMenuItem3.setSelected(true);
    this.cbMenuItem3.setMnemonic(90);
    add(this.cbMenuItem3);
    localButtonGroup.add(this.cbMenuItem3);
        
    this.cbMenuItem4 = new JCheckBoxMenuItem("Motif");              //A button used for activating look and feel 4
    this.cbMenuItem4.setMnemonic(90); 
    add(this.cbMenuItem4); 
    localButtonGroup.add(this.cbMenuItem4);	   
                             
  }
  /**
   * methods to get cbMenuItem1~4
   */  
  public JCheckBoxMenuItem getCbMenuItem1(){
    return cbMenuItem1;
  }
  public JCheckBoxMenuItem getCbMenuItem2(){
    return cbMenuItem2;
  }
  public JCheckBoxMenuItem getCbMenuItem3(){
    return cbMenuItem3;
  }
  public JCheckBoxMenuItem getCbMenuItem4(){
    return cbMenuItem4;
  }
  
  public void setStyle(Group localGroup, int num){
	  if(num==1)
		  selectedStyle="javax.swing.plaf.metal.MetalLookAndFeel";
	  else if(num ==2)
	      selectedStyle="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
	  else if(num ==3)
	      selectedStyle="com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
	  else
		  selectedStyle="com.sun.java.swing.plaf.motif.MotifLookAndFeel";	  
	  try //prefer
      {
          //localJFrame.setDefaultLookAndFeelDecorated(true);
          UIManager.setLookAndFeel(selectedStyle);
          SwingUtilities.updateComponentTreeUI(localGroup);
      } catch (UnsupportedLookAndFeelException localUnsupportedLookAndFeelException) {
          System.err.println("Unsupported LookAndFeel: "+selectedStyle);
      } catch (ClassNotFoundException localClassNotFoundException) {
          System.err.println("LookAndFeel class not found: "+selectedStyle);
      } catch (InstantiationException localInstantiationException) {
          System.err.println("Could not load LookAndFeel: "+selectedStyle);
      } catch (IllegalAccessException localIllegalAccessException) {
          System.err.println("Cannot use LookAndFeel: "+selectedStyle);
      } 
  }
  
  
    

}  
